<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\ChOperationLog;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\FrdCircTaskRequest;
use App\CustHub\Service\ChFriendCircleTaskService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Mine\Annotation\Resubmit;

#[Controller(prefix: 'ch/frdCircTask'),ApiAuth,VerifySignature]
class ChFriendCircleTaskController extends BaseController
{
    #[Inject]
    protected ChFriendCircleTaskService $service;

    /**
     * 任务列表
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('list')]
    public function list(): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->list($this->request->all()));
    }

    #[PostMapping('getInfo')]
    public function getInfo(): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getInfo($this->request->all()));
    }

    /**
     * 下发机器人列表
     * @param FrdCircTaskRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('robotList')]
    public function robotList(FrdCircTaskRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->robotList($request->all()));
    }

    /**
     * 新增
     * @param FrdCircTaskRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('save'),Resubmit,ChOperationLog]
    public function save(FrdCircTaskRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success(['id'=>$this->service->save($request->all())]);
    }

    /**
     * 编辑
     * @param FrdCircTaskRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('update'),ChOperationLog]
    public function updateTask(FrdCircTaskRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->updateTask($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 取消任务
     * @param FrdCircTaskRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('cancelTask'),ChOperationLog]
    public function cancelTask(FrdCircTaskRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->cancelTask($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 删除朋友圈
     * @param FrdCircTaskRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('deleteFriendCircle'),ChOperationLog]
    public function deleteFriendCircle(FrdCircTaskRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->deleteFriendCircle($request->all()) ? $this->success('删除朋友圈任务执行中，请稍后刷新页面查看删除状态') : $this->error();
    }

    /**
     * 追加评论
     * @param FrdCircTaskRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('addComments'),ChOperationLog]
    public function addComments(FrdCircTaskRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->addComments($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 追加评论
     * @param FrdCircTaskRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('delete'),ChOperationLog]
    public function deleteTask(FrdCircTaskRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->deleteTask($request->all()) ? $this->success('删除成功') : $this->error('删除失败');
    }

    #[PostMapping('getTaskList'),ChOperationLog]
    public function getTaskList(FrdCircTaskRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getTaskList($request->all()));
    }
}